//
//  SLMineLogoff.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/19.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit

class SLMineLogoff: UIViewController {
    var handle:SLBlock?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = rgba(hex: "#000000", a: 0.5)
        let backView = UIView()
        backView.backgroundColor = .white
        self.view.addSubview(backView)
        backView.snp.makeConstraints { make in
            make.width.equalTo(303)
            make.height.equalTo(290)
            make.centerY.equalToSuperview().offset(-70)
            make.centerX.equalToSuperview()
        }
        backView.layer.masksToBounds = true
        backView.layer.cornerRadius = 24
        
        let icon = UIImageView()
        icon.image = IMAGE("icon-log out")
        backView.addSubview(icon)
        icon.snp.makeConstraints { make in
            make.width.equalTo(186)
            make.height.equalTo(140)
            make.top.equalTo(24)
            make.centerX.equalToSuperview()
        }
        
        let titleL = UILabel()
        titleL.font = SLFontConfig.medium20
        titleL.text = "Are you sure to logout?"
        backView.addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.top.equalTo(164)
            make.centerX.equalToSuperview()
        }
        
        let button = UIButton(type: .custom)
        button.setTitle("confirm", for: .normal)
        button.backgroundColor = rgba(hex: "#1608EC")
        button.titleLabel?.font = SLFontConfig.medium16
        backView.addSubview(button)
        button.snp.makeConstraints { make in
            make.width.equalTo(177)
            make.height.equalTo(44)
            make.bottom.equalTo(-20)
            make.centerX.equalToSuperview()
        }
        button.layer.masksToBounds = true
        button.layer.cornerRadius = 22
        button.addTarget(self, action: #selector(logoutAction), for: .touchUpInside)
        
        let closeBtn = UIButton(type: .custom)
        closeBtn.setBackgroundImage(IMAGE("icon_clos"), for: .normal)
        self.view.addSubview(closeBtn)
        closeBtn.snp.makeConstraints { make in
            make.width.height.equalTo(34)
            make.top.equalTo(backView.snp.bottom).offset(24)
            make.centerX.equalToSuperview()
        }
        closeBtn.addTarget(self, action: #selector(closeAction), for: .touchUpInside)
    }
    @objc func logoutAction(){
        if let blcok = self.handle{
            blcok(0)
        }
        self.dismiss(animated: true)
    }
    @objc func closeAction(){
        self.dismiss(animated: true)
    }
    lazy var backView:UIView = {
        let v = UIView()
        v.backgroundColor = .white
        return v
    }()
    lazy var icon:UIImageView = {
        let v = UIImageView()
        return v
    }()
    class func showAlert(page:UIViewController,handle:SLBlock?){
        let alert = SLMineLogoff()
        alert.modalPresentationStyle = .overCurrentContext
        alert.modalTransitionStyle = .crossDissolve
        alert.handle = handle
        page.present(alert, animated: true)
    }
}
